import AxiosMethods from "@/util/AxiosMethods"
const state = {
    project: {}
}
const getters = {}
const mutations = {
    // 支持项目，给项目加钱
    supportMoney(state,money){
        state.project.amount += money
    },
    // 初始化项目信息，同时在图片路径前加上src/assets/images/
    InitOneProject(state,project){
        state.project = project
        state.project.photo="src/assets/images/"+state.project.photo
    }
}
const actions = {
    // 获取单个项目信息
    async getOneProject({ commit }, id) {
        try{
            const response = await AxiosMethods.post(`/project/select`,{pid:id})
            // console.log("获取的项目信息",response.data.data[0])
            commit('InitOneProject',response.data.data[0])
        }catch(error){
            console.log(error)
        }
    },
    // 直接改变项目资金，用于测试
    /*async collectMoneys({ commit }, data){
        try{
            const params={
                pid:data.pid,
                amount:data.money
            }
            const response = await AxiosMethods.put(`/project`,params)
            // console.log("项目支持结果",response.data.code)
            if(response.data.code === 1){
                // console.log("项目支持成功")
            }
        }catch(error){
            console.log(error)
        }
    }*/
}

export default {
    namespaced: true,
  state,
  getters,
  mutations,
  actions
}